load("@rules_rust//rust:defs.bzl", "rust_static_library")
load("//bazel:rust_cxx_bridge.bzl", "rust_cxx_bridge")
load(
    "//bazel:skia_rules.bzl",
    "skia_cc_library",
    "skia_filegroup",
)

skia_filegroup(
    name = "rs_srcs",
    srcs = ["FFI.rs"],
)

skia_filegroup(
    name = "cxx_bridge_srcs",
    srcs = ["FFI.rs"],
)

# Note: the `hdrs` of the `utils` target are included in *two* `.gni` lists
# (`skia_codec_rust_png` and `skia_encode_rust_png_srcs`) - this works only
# because this is a header-only library.  If `utils` needs `srcs` in the
# future, then a separate `.gni` list may be required.
skia_cc_library(
    name = "utils",
    hdrs = ["UtilsForFFI.h"],
    features = ["layering_check"],
    visibility = ["//experimental/rust_png:__subpackages__"],
    deps = ["//:core"],
)

skia_cc_library(
    name = "ffi_cpp",
    hdrs = ["FFI.h"],
    features = ["layering_check"],
    visibility = [
        "//experimental/rust_png:__subpackages__",
    ],
)

rust_cxx_bridge(
    name = "cxx_bridge",
    src = "FFI.rs",
    visibility = [
        "//experimental/rust_png:__subpackages__",
    ],
    deps = [":ffi_cpp"],
)

rust_static_library(
    name = "ffi_rs",
    srcs = [":rs_srcs"],
    rustc_flags = ["-Dwarnings"],
    visibility = [
        "//experimental/rust_png:__subpackages__",
    ],
    deps = [
        ":ffi_cpp",
        "@cxx",
        "@rust_png//:png",
    ],
)
